package com.example.unisys.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class UploadUtil {

    // 项目根路径下的目录  -- SpringBoot static 目录相当于是根路径下（SpringBoot 默认）
    //public final static String IMG_PATH_PREFIX = "File";

    public static File getImgDirFile(){

        // 构建上传文件的存放 "文件夹" 路径
        String fileDirPath = new String("/root/sites/cdn/");
        //String fileDirPath = new String("./static/file");
        File fileDir = new File(fileDirPath);
        if(!fileDir.exists()){
            // 递归生成文件夹
            fileDir.mkdirs();
        }
        return fileDir;
    }

    public static File getPhotoPath(){
        String fileDirPath = new String("/root/sites/cdn/photos/");
        //String fileDirPath = new String("./static/file");
        File fileDir = new File(fileDirPath);
        if(!fileDir.exists()){
            // 递归生成文件夹
            fileDir.mkdirs();
        }
        return fileDir;
    }


    public static int writeFile(String content,String path ){
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(path));
            bw.write(content);
            bw.close();
        }catch(Exception e){
            e.printStackTrace();
            return 0;
        }
        return 1;
    }
}

